home *** CD-ROM | disk | FTP | other *** search
Text File | 1988-04-14 | 22.4 KB | 985 lines | [TEXT/MPS ] |
- { PalFun by Steve Sheets 3/88 }
-
- { Palette Manager Sample Program designed for MacTutor. }
- { It demonstrate various Palette Animation effects. }
-
- PROGRAM PalFun;
-
- USES MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, PaletteMgr, PickerIntf;
-
- CONST appleM = 301; {Menu ID Constants}
- fileM = 302;
- editM = 303;
- winM = 304;
- menuCount = 304;
-
- numWindows = 9; {Window ID Constants}
- redW = 1;
- greenW = 2;
- blueW = 3;
- curW = 4;
- ballW = 5;
- shapeW = 6;
- rainbowW = 7;
- fadeW = 8;
-
- StrID = 300; {Various Resource ID Constants}
- AlertID = 300;
- FadeID = 300;
- ShapeID = 301;
-
- MaxCT = 2048; {Max Numbers in CLUT (usually only use 256}
-
- ColorInc = $200; {Amount difference between Color rings}
- ColorStart = $FE00; {Start Color Rings}
-
- {My Version of the CLUT data structure (used for stuffing values).}
- TYPE MyCSpecArray = ARRAY[0..MaxCT] OF ColorSpec;
-
- MyCTabHandle = ^MyCTabPtr;
- MyCTabPtr = ^MyColorTable;
- MyColorTable = RECORD
- ctSeed : LONGINT;
- ctFlag : INTEGER;
- ctSize : INTEGER;
- ctTable : MyCSpecArray;
- END;
-
- {Standard Variables (Menus, Window Pointer, Window Record)}
- {And Palette Handles (1 per Window). }
- VAR myMenus : ARRAY[appleM..menuCount] OF MenuHandle;
- MyWindow : ARRAY[1..numWindows] of WindowPtr;
- MyPalette : ARRAY[1..numWindows] of PaletteHandle;
- dragRect : Rect;
- doneFlag : BOOLEAN;
-
- {******************** General Tools ********************}
-
- {Returns true if the Mac had Color Quickdraw.}
- FUNCTION ColorQDExists : boolean;
- CONST
- ROM85Loc = $28E;
- TwoHighMask = $C000;
- TYPE
- WordPtr = ^INTEGER;
- VAR
- Wd : WordPtr;
- BEGIN
- Wd := POINTER(ROM85Loc);
- ColorQDExists := (BitAnd(Wd^, TwoHighMask) = 0);
- END;
-
- {Stuffs Red, Green & Blue into RGBColor}
- PROCEDURE SetRGB(VAR RGB:RGBColor;R,G,B:INTEGER);
- BEGIN
- RGB.Red:=R;
- RGB.Green:=G;
- RGB.Blue:=B;
- END;
-
- {Copies RGBColor into RGBColor}
- PROCEDURE CopyRGB(RGBsrc:RGBColor;VAR RGBdest:RGBColor);
- BEGIN
- RGBdest.Red:=RGBsrc.Red;
- RGBdest.Green:=RGBsrc.Green;
- RGBdest.Blue:=RGBsrc.Blue;
- END;
-
- {Delays a set length time. usually until}
- { the screen in refreshed (prevents ripples)}
- PROCEDURE DoDelay(N:INTEGER);
- VAR L:LONGINT;
- BEGIN
- L:=TickCount+N;
- WHILE L>TickCount DO ;
- END;
-
- {Using 16 Bit Unsigned Integers: C:=A/B}
- PROCEDURE UnSignedDiv(A,B:INTEGER;VAR C:INTEGER);
- VAR L:LongInt;
- BEGIN
- IF A<0
- THEN L:=A+65536
- ELSE L:=A;
- C:=LoWord(L DIV B);
- END;
-
- {Using 16 Bit Unsigned Integers: A:=A+B}
- PROCEDURE UnSignedAdd(VAR A:INTEGER;B:INTEGER);
- VAR L:LongInt;
- BEGIN
- IF A<0
- THEN L:=A+65536+B
- ELSE L:=A+B;
- A:=LoWord(L);
- END;
-
- {Using 16 Bit Unsigned Integers: A:=A-B}
- PROCEDURE UnSignedSub(VAR A:INTEGER;B:INTEGER);
- VAR L:LongInt;
- BEGIN
- IF A<0
- THEN L:=A+65536-B
- ELSE L:=A-B;
- A:=LoWord(L);
- END;
-
- {******************** Color Table Tools ********************}
-
- {Given number of Colors to be placed in it, creates a blank CLUT. Gives it}
- { an unique Seed and correct value, but no colors.}
- FUNCTION NewCT (N : integer) : CTabHandle;
- VAR
- MyCT : MyCTabHandle;
- count : integer;
- BEGIN
- MyCT := NIL;
- IF (N > 0) AND (N <= MaxCT) THEN
- BEGIN
- MyCT := POINTER(NewHandle((N * SIZEOF(ColorSpec)) + (2 * SIZEOF(integer)) + SIZEOF(longint)));
- IF MyCT <> NIL THEN
- WITH MyCT^^ DO
- BEGIN
- ctSeed := GetCTSeed;
- ctFlag := 0;
- ctSize := N - 1;
- FOR count := 0 TO N - 1 DO
- WITH ctTable[count] DO
- BEGIN
- value := count;
- SetRGB(rgb,0,0,0);
- END;
- END;
- END;
- NewCT := POINTER(MyCT);
- END;
-
- {Stuffs an RGB value in the Nth Color (numbered 0 to N) of the CLUT.}
- PROCEDURE SetCTEntry (C : CTabHandle;
- N, R, G, B : INTEGER);
- VAR
- MyCT : MyCTabHandle;
- BEGIN
- MyCT := POINTER(C);
- SetRGB(MyCT^^.ctTable[n].rgb,R,G,B);
- END;
-
- {******************** Red ********************}
-
- {Red Window displays encompassing red-shaded circles.}
- {This creates a 3-D Globe effect.}
-
- {Create Red Window/Palette with NewPalette & SetEntryColor commands.}
- PROCEDURE MakeRed;
- VAR tempRect : rect;
- tempRGB : RGBColor;
- S : str255;
- count : integer;
- BEGIN
- SetRect(tempRect, 20, 40, 320, 340);
- GetIndString(S, StrID, 1);
- MyWindow[redW] := NewCWindow(nil, tempRect, S, true, noGrowDocProc, POINTER(-1), true, 0);
-
- MyPalette[redW] := NewPalette(128, NIL, pmTolerant, 0);
- SetRGB(tempRGB,ColorStart,0,0);
- FOR count := 0 TO 127 DO
- BEGIN
- SetEntryColor(MyPalette[redW], count, tempRGB);
- UnSignedSub(tempRGB.red,ColorInc);
- END;
-
- SetPalette(MyWindow[redW], MyPalette[redW], true);
- END;
-
- {Draw the Red Window using RGBForeColor.}
- PROCEDURE DoRedUpdate;
- VAR
- tempRect : rect;
- tempRGB : RGBColor;
- count : integer;
- BEGIN
- SetRect(tempRect, 22, 22, 278, 278);
- SetRGB(tempRGB,ColorStart,0,0);
- FOR count := 0 TO 127 DO
- BEGIN
- RGBForeColor(tempRGB);
- PaintOval(tempRect);
- InsetRect(tempRect, 1, 1);
- UnSignedSub(tempRGB.red,ColorInc);
- END;
- END;
-
- {******************** Green ********************}
-
- {Green Window displays a Green Globe.}
-
- {Create Green Window/Palette with NewPalette command & CLUT procedures.}
- PROCEDURE MakeGreen;
- VAR tempRect : rect;
- tempRGB : RGBColor;
- tempCT : CTabHandle;
- Col : INTEGER;
- S : str255;
- count : integer;
- BEGIN
- SetRect(tempRect, 40, 60, 340, 360);
- GetIndString(S, StrID, 2);
- MyWindow[greenW] := NewCWindow(nil, tempRect, S, true, noGrowDocProc, POINTER(-1), true, 0);
-
- tempCT := NewCT(128);
- Col := ColorStart;
- FOR count := 0 TO 127 DO
- BEGIN
- SetCTEntry(tempCT, count, 0, Col, 0);
- UnSignedSub(Col,ColorInc);
- END;
- MyPalette[greenW] := NewPalette(128, tempCT, pmTolerant, 0);
- DisposHandle(Handle(tempCT));
-
- SetPalette(MyWindow[greenW], MyPalette[greenW], true);
- END;
-
- {Draw the Green Window using PmForeColor.}
- PROCEDURE DoGreenUpdate;
- VAR
- tempRect : rect;
- count : integer;
- BEGIN
- SetRect(tempRect, 22, 22, 278, 278);
- FOR count := 0 TO 127 DO
- BEGIN
- PmForeColor(count);
- PaintOval(tempRect);
- InsetRect(tempRect, 1, 1);
- END;
- END;
-
- {******************** Blue ********************}
-
- {Display a Blue Globe (like Green Window), but now the colors }
- {are set up for better displaying (ie. Color Priority).}
-
- {Create Green Window/Palette with NewPalette command & CLUT procedures.}
-
- PROCEDURE MakeBlue;
- VAR tempRect : rect;
- tempRGB : RGBColor;
- tempCT : CTabHandle;
- Col : INTEGER;
- S : str255;
- h, v : integer;
- BEGIN
- SetRect(tempRect, 60, 80, 360, 380);
- GetIndString(S, StrID, 3);
- MyWindow[blueW] := NewCWindow(nil, tempRect, S, true, noGrowDocProc, POINTER(-1), true, 0);
-
- tempCT := NewCT(128);
- Col := ColorStart;
- FOR h := 0 TO 15 DO
- FOR v := 0 TO 7 DO
- BEGIN
- SetCTEntry(tempCT, (v * 16) + h, 0, 0, Col);
- UnSignedSub(Col,ColorInc);
- END;
- MyPalette[blueW] := NewPalette(128, tempCT, pmTolerant, 0);
- DisposHandle(Handle(tempCT));
-
- SetPalette(MyWindow[blueW], MyPalette[blueW], true);
- END;
-
- {Draw the Blue Window using RGBForeColor.}
- PROCEDURE DoBlueUpdate;
- VAR
- tempRect : rect;
- tempRGB : RGBColor;
- count : integer;
- BEGIN
- SetRect(tempRect, 22, 22, 278, 278);
- SetRGB(tempRGB,0,0,ColorStart);
- FOR count := 0 TO 127 DO
- BEGIN
- RGBForeColor(tempRGB);
- PaintOval(tempRect);
- InsetRect(tempRect, 1, 1);
- UnSignedSub(tempRGB.Blue,ColorInc);
- END;
- END;
-
- {******************** Current Color ********************}
-
- {Displays the Current Color Enviroment}
-
- {Create the current Color Window using Explicit colors }
- {(Does not have to set the colors).}
- PROCEDURE MakeCur;
- VAR tempRect : rect;
- S : str255;
- BEGIN
- SetRect(tempRect, 100, 80, 420, 400);
- GetIndString(S, StrID, 4);
- MyWindow[curW] := NewCWindow(nil, tempRect, S, true, noGrowDocProc, POINTER(-1), true, 0);
- MyPalette[curW] := NewPalette(256, NIL, pmExplicit, 0);
- SetPalette(MyWindow[curW], MyPalette[curW], true);
- END;
-
- {Draws the current Graphic Device Colors.}
- PROCEDURE DoCurUpdate;
- VAR
- x, y, n : integer;
- tempRect : rect;
- BEGIN
- n := 0;
- FOR y := 0 TO 15 DO
- FOR x := 0 TO 15 DO
- BEGIN
- PmForeColor(n);
- SetRect(tempRect, x * 20, y * 20, (x + 1) * 20, (y + 1) * 20);
- PaintRect(tempRect);
- n := n + 1;
- END;
- END;
-
- {******************** Ball ********************}
-
- {Simple Palette Animation of a Ball Across the Screen}
-
- {Create the Ball Animation Window using Animated colors.}
- PROCEDURE MakeBall;
- VAR tempRect : rect;
- tempRGB : RGBColor;
- S : str255;
- count : integer;
- BEGIN
- SetRect(tempRect, 100, 120, 400, 420);
- GetIndString(S, StrID, 5);
- MyWindow[ballW] := NewCWindow(nil, tempRect, S, true, noGrowDocProc, POINTER(-1), true, 0);
- MyPalette[ballW] := NewPalette(19, NIL, pmAnimated, 0);
-
- SetRGB(tempRGB,$FFFF,$FFFF,$FFFF);
- SetEntryColor(MyPalette[ballW], 0, tempRGB);
- SetRGB(tempRGB,0,0,0);
- SetEntryColor(MyPalette[ballW], 1, tempRGB);
- tempRGB.blue := $FFFF;
- SetEntryColor(MyPalette[ballW], 2, tempRGB);
- tempRGB.blue := 0;
- tempRGB.red := $FFFF;
- FOR count := 3 TO 18 DO
- SetEntryColor(MyPalette[ballW], count, tempRGB);
- SetPalette(MyWindow[ballW], MyPalette[ballW], true);
- END;
-
- {Draw the Balls in the window using PmForeColor.}
- PROCEDURE DoBallUpdate;
- VAR
- R : rect;
- count : integer;
- BEGIN
- SetRect(R, 0, 0, 10000, 10000);
- PmForeColor(18);
- PaintRect(R);
-
- FOR count := 2 TO 17 DO
- BEGIN
- R.top := 16 * count;
- R.left := R.top;
- R.bottom := R.top + 16;
- R.right := R.bottom;
- PmForeColor(count);
- PaintOval(R);
- END;
- END;
-
- {Animate the Ball through the window using AnimateEntry.}
- PROCEDURE AnimBall;
- VAR
- R, B : RGBcolor;
- time, count, temp : integer;
- BEGIN
- SetRGB(R,$FFFF,0,0);
-
- SetRGB(B,0,0,$FFFF);
-
- FOR time := 1 TO 10 DO
- FOR count := 2 TO 17 DO
- BEGIN
- IF count = 17
- THEN temp := 2
- ELSE temp:=count+1;
- DoDelay(1);
- AnimateEntry(MyWindow[ballW], count, R);
- AnimateEntry(MyWindow[ballW], temp, B);
- END;
- END;
-
- {******************** Shape ********************}
-
- {Given 3 arbitrary regions (Black/White images), calculates how}
- {to draw the window so that the images can be shuffled through
- {quickly.}
-
- {Create the Shape Animation Window}
- {('pltt' is automatically loaded in).}
- PROCEDURE MakeShape;
- BEGIN
- MyWindow[shapeW] := GetNewCWindow(ShapeID, nil, POINTER(-1));
- END;
-
- {Draws Shape. aRgn,bRgn,cRgn are the arbitrary images.}
- PROCEDURE DoShapeUpdate;
- VAR aRgn,bRgn,cRgn,TempRgn: RgnHandle;
- count:INTEGER;
- TempRect:Rect;
- PROCEDURE DrawTriag(h,v:INTEGER);
- BEGIN
- MoveTo(h+25,v);
- Line(-25,50);
- Line(50,0);
- Line(-25,-50);
- END;
- BEGIN
- aRgn:=NewRgn;
- OpenRgn;
- SetRect(tempRect,10,10,60,60);
- FrameOval(tempRect);
- SetRect(tempRect,120,10,170,60);
- FrameRect(tempRect);
- SetRect(tempRect,120,80,170,130);
- FrameRect(tempRect);
- SetRect(tempRect,190,10,240,60);
- FrameRect(tempRect);
- SetRect(tempRect,190,80,240,130);
- FrameRect(tempRect);
- SetRect(tempRect,10,80,110,81);
- FOR count:=1 TO 25 DO BEGIN
- FrameRect(tempRect);
- OffSetRect(tempRect,0,2);
- END;
- CloseRgn(aRgn);
- bRgn:=NewRgn;
- OpenRgn;
- SetRect(tempRect,35,10,85,60);
- FrameOval(tempRect);
- SetRect(tempRect,120,10,170,60);
- FrameOval(tempRect);
- SetRect(tempRect,120,80,170,130);
- FrameOval(tempRect);
- SetRect(tempRect,190,10,240,60);
- FrameOval(tempRect);
- SetRect(tempRect,190,80,240,130);
- FrameOval(tempRect);
- SetRect(tempRect,10,80,11,130);
- FOR count:=1 TO 25 DO BEGIN
- FrameRect(tempRect);
- OffSetRect(tempRect,4,0);
- END;
- CloseRgn(bRgn);
- cRgn:=NewRgn;
- OpenRgn;
- SetRect(tempRect,60,10,110,60);
- FrameOval(tempRect);
- DrawTriag(120,10);
- DrawTriag(120,80);
- DrawTriag(190,10);
- DrawTriag(190,80);
- MoveTo(60,80);
- Line(50,25);
- Line(-50,25);
- Line(-50,-25);
- Line(50,-25);
- CloseRgn(cRgn);
- TempRgn:=NewRgn;
-
- {This Region will always be Red (Background)}
- PmForeColor(0);
- SetRect(tempRect,-32000,-32000,32000,32000);
- PaintRect(tempRect);
-
- {This region will start Blue, change Red, stay Red}
- PmForeColor(1);
- DiffRgn(aRgn,bRgn,TempRgn);
- DiffRgn(TempRgn,cRgn,TempRgn);
- PaintRgn(TempRgn);
-
- {This region will be Red,Blue,Red}
- PmForeColor(2);
- DiffRgn(bRgn,aRgn,TempRgn);
- DiffRgn(TempRgn,cRgn,TempRgn);
- PaintRgn(TempRgn);
-
- {This region will be Blue,Blue,Red}
- PmForeColor(3);
- SectRgn(aRgn,bRgn,TempRgn);
- PaintRgn(TempRgn);
-
- {This region will be Red,Red,Blue}
- PmForeColor(4);
- DiffRgn(cRgn,aRgn,TempRgn);
- DiffRgn(TempRgn,bRgn,TempRgn);
- PaintRgn(TempRgn);
-
- {This region will be Blue,Red,Blue}
- PmForeColor(5);
- SectRgn(aRgn,cRgn,TempRgn);
- PaintRgn(TempRgn);
-
- {This region will be Red,Blue,Blue}
- PmForeColor(6);
- SectRgn(bRgn,cRgn,TempRgn);
- PaintRgn(TempRgn);
-
- {This Region will always be Blue}
- PmForeColor(7);
- SectRgn(aRgn,bRgn,TempRgn);
- SectRgn(cRgn,TempRgn,TempRgn);
- PaintRgn(TempRgn);
-
- DisposeRgn(aRgn);
- DisposeRgn(bRgn);
- DisposeRgn(cRgn);
- DisposeRgn(TempRgn);
- END;
-
- {Animate the Shape image using AnimatePalette/CLUT resouces.}
- PROCEDURE AnimShape;
- VAR count:INTEGER;
- MyCLUT:ARRAY[1..3] OF CTabHandle;
- BEGIN
- FOR count:=1 to 3
- DO MyCLUT[count]:=GetCTable(count+300);
-
- DoDelay(1);
- AnimatePalette(MyWindow[shapeW],MyCLUT[2],0,0,8);
- DoDelay(60);
- AnimatePalette(MyWindow[shapeW],MyCLUT[3],0,0,8);
- DoDelay(60);
- AnimatePalette(MyWindow[shapeW],MyCLUT[1],0,0,8);
- DoDelay(50);
-
- FOR count:=1 TO 5 DO BEGIN
- DoDelay(10);
- AnimatePalette(MyWindow[shapeW],MyCLUT[2],0,0,8);
- DoDelay(10);
- AnimatePalette(MyWindow[shapeW],MyCLUT[3],0,0,8);
- DoDelay(10);
- AnimatePalette(MyWindow[shapeW],MyCLUT[1],0,0,8);
- END;
-
- DoDelay(60);
-
- FOR count:=1 TO 5 DO BEGIN
- DoDelay(1);
- AnimatePalette(MyWindow[shapeW],MyCLUT[2],0,0,8);
- DoDelay(1);
- AnimatePalette(MyWindow[shapeW],MyCLUT[3],0,0,8);
- DoDelay(1);
- AnimatePalette(MyWindow[shapeW],MyCLUT[1],0,0,8);
- END;
-
- FOR count:=1 to 3
- DO DisposCTable(MyCLUT[count]);
- END;
-
- {******************** Rainbow ********************}
-
- {Demonstrates the Rainbow Effect (Rotating Circle,}
- {Moving Bands and Expanding Circle).
-
- {Create the Rainbow Animation Window.}
- PROCEDURE MakeRainbow;
- VAR tempRect : rect;
- tempRGB : RGBColor;
- S : str255;
- tempHSV : HSVColor;
- count : integer;
- BEGIN
- SetRect(tempRect, 50, 160, 590, 400);
- GetIndString(S, StrID, 6);
- MyWindow[rainbowW] := NewCWindow(nil, tempRect, S, true, noGrowDocProc, POINTER(-1), true, 0);
- MyPalette[rainbowW] := NewPalette(122, NIL, pmAnimated, 0);
-
- SetRGB(tempRGB,$FFFF,$FFFF,$FFFF);
- SetEntryColor(MyPalette[rainbowW], 0, tempRGB);
- SetRGB(tempRGB,0,0,0);
- SetEntryColor(MyPalette[rainbowW], 1, tempRGB);
- tempHSV.saturation := $FFFF;
- tempHSV.value := $FFFF;
- FOR count := 1 TO 120 DO
- BEGIN
- tempHSV.hue := ($0FFFF*count) DIV 120;
- HSV2RGB(tempHSV, tempRGB);
- SetEntryColor(MyPalette[rainbowW], count+1, tempRGB);
- END;
- SetPalette(MyWindow[rainbowW], MyPalette[rainbowW], true);
- END;
-
- {Draws the rays of the Rainbow.}
- PROCEDURE DoRainbowUpdate;
- VAR count:INTEGER;
- tempRect,CRect:Rect;
- BEGIN
- SetRect(tempRect, 0, 0, 480, 240);
- PmForeColor(0);
- PaintRect(tempRect);
- SetRect(tempRect, 0, 0, 240, 240);
- SetRect(CRect, 300, 0, 540, 240);
- FOR count := 0 TO 119 DO
- BEGIN
- PmForeColor(count+2);
- PaintArc(tempRect,count*3,3);
-
- MoveTo(240,count);
- Line(60,0);
- MoveTo(240,count+120);
- Line(60,0);
-
- PaintOval(CRect);
- InsetRect(CRect,1,1);
- END;
- END;
-
- {Rotates all the entries in the CLUT one position.}
- PROCEDURE BumpCTEntry(C:CTabHandle);
- VAR tempRGB:RGBcolor;
- MyCT : MyCTabHandle;
- count:INTEGER;
- BEGIN
- MyCT := POINTER(C);
- WITH MyCT^^ DO BEGIN
- CopyRGB(ctTable[0].rgb,tempRGB);
-
- FOR count:=1 TO ctSize DO
- CopyRGB(ctTable[count].rgb,ctTable[count-1].rgb);
-
- CopyRGB(tempRGB,ctTable[ctSize].rgb);
- END;
- END;
-
- {Animate the Rainbow using AnimatePalette. This one}
- {creates and manilpulates it's CLUT directly.}
- PROCEDURE AnimRainbow;
- VAR count:INTEGER;
- tempRGB : RGBColor;
- tempCT : CTabHandle;
- BEGIN
- tempCT := NewCT(120);
- FOR count := 1 TO 120 DO BEGIN
- GetEntryColor(MyPalette[rainbowW],count+1,tempRGB);
- SetCTEntry(tempCT, count-1, tempRGB.red, tempRGB.green, tempRGB.blue);
- END;
-
- FOR count:=1 TO 360 DO BEGIN
- BumpCTEntry(tempCT);
- DoDelay(1);
- AnimatePalette(MyWindow[rainbowW],tempCT,0,2,120);
- END;
- DisposHandle(Handle(tempCT));
- END;
-
- {******************** Fade ********************}
-
- {Demonstrates the Fade effect}
-
- {Create the Fade Animation Window (uses Palette resource).}
- PROCEDURE MakeFade;
- BEGIN
- MyWindow[fadeW] := GetNewCWindow(FadeID, nil, POINTER(-1));
- END;
-
- {Draws Fade window}
- PROCEDURE DoFadeUpdate;
- VAR tempRect:Rect;
- count:INTEGER;
- BEGIN
- PmForeColor(0);
- SetRect(tempRect,-32000,-32000,32000,32000);
- PaintRect(tempRect);
-
- FOR count:=1 TO 4 DO BEGIN
- PmForeColor(count);
- SetRect(tempRect,((count-1)*100)+10,10,(count*100)-10,90);
- PaintOval(tempRect);
- END;
-
- FOR count:=5 TO 8 DO BEGIN
- PmForeColor(count);
- SetRect(tempRect,((count-5)*100)+10,110,((count-4)*100)-10,190);
- PaintOval(tempRect);
- END;
- END;
-
- {Animate the Fade.}
- PROCEDURE AnimFade;
- CONST FadeStep = 60;
- VAR count,E:INTEGER;
- Buf,Inc,Start: ARRAY[0..8] OF RGBColor;
- BEGIN
- SetRGB(Buf[0],-1,-1,-1);
- SetRGB(Buf[1],0,0,0);
- SetRGB(Buf[2],-1,0,0);
- SetRGB(Buf[3],0,-1,0);
- SetRGB(Buf[4],0,0,-1);
- SetRGB(Buf[5],0,-1,-1);
- SetRGB(Buf[6],-1,0,-1);
- SetRGB(Buf[7],-1,-1,0);
- SetRGB(Buf[8],30000,30000,30000);
- FOR E:=0 TO 8 DO BEGIN
- CopyRGB(Buf[E],Start[E]);
- UnSignedDiv(Buf[E].Red,FadeStep,Inc[E].Red);
- UnSignedDiv(Buf[E].Green,FadeStep,Inc[E].Green);
- UnSignedDiv(Buf[E].Blue,FadeStep,Inc[E].Blue);
- END;
-
- FOR count:=FadeStep-1 DOWNTO 1 DO BEGIN
- FOR E:=0 TO 8 DO BEGIN
- DoDelay(1);
- UnSignedSub(Buf[E].Red,Inc[E].Red);
- UnSignedSub(Buf[E].Green,Inc[E].Green);
- UnSignedSub(Buf[E].Blue,Inc[E].Blue);
- AnimateEntry(MyWindow[fadeW],E,Buf[E]);
- END;
- END;
-
- DoDelay(1);
- FOR E:=0 TO 8 DO BEGIN
- SetRGB(Buf[E],0,0,0);
- AnimateEntry(MyWindow[fadeW],E,Buf[E]);
- END;
-
- DoDelay(90);
-
- FOR count:=1 TO FadeStep-1 DO BEGIN
- FOR E:=0 TO 8 DO BEGIN
- DoDelay(1);
- UnSignedAdd(Buf[E].Red,Inc[E].Red);
- UnSignedAdd(Buf[E].Green,Inc[E].Green);
- UnSignedAdd(Buf[E].Blue,Inc[E].Blue);
- AnimateEntry(MyWindow[fadeW],E,Buf[E]);
- END;
- END;
-
- DoDelay(1);
- FOR E:=0 TO 8
- DO AnimateEntry(MyWindow[fadeW],E,Buf[E]);
- END;
-
- {******************** Main Portion Programs ********************}
-
- {Set Up the normal Mac Interface}
- PROCEDURE SetUp;
- VAR count : integer;
- BEGIN
- {Standard Mac Program setup}
- InitGraf(@thePort);
- InitFonts;
- FlushEvents(everyEvent, 0);
- InitWindows;
- InitMenus;
- TEInit;
- InitDialogs(NIL);
- InitCursor;
-
- FOR count := appleM TO menuCount DO
- myMenus[count] := GetMenu(count);
- AddResMenu(myMenus[appleM], 'DRVR');
- FOR count := appleM TO menuCount DO
- InsertMenu(myMenus[count], 0);
- DrawMenuBar;
-
- WITH screenBits.bounds DO
- SetRect(dragRect, 4, 24, right - 4, bottom - 4);
- doneFlag := FALSE;
-
- FOR count:=1 TO numWindows DO BEGIN
- MyWindow[count]:=NIL;
- MyPalette[count]:=NIL;
- END;
- END;
-
- {Given a Window ID number, close Window/Palette}
- PROCEDURE CloseIt (N:INTEGER);
- BEGIN
- IF (N>0) AND (N<=numWindows) THEN BEGIN
- IF MyPalette[N] <> NIL THEN
- DisposePalette(MyPalette[N]);
- MyPalette[N]:=NIL;
- IF MyWindow[N]<> NIL THEN
- DisposeWindow(MyWindow[N]);
- MyWindow[N]:=NIL;
- END;
- END;
-
- {Gets the Front most Window ID number.}
- FUNCTION GetWindowNum(W:WindowPtr):INTEGER;
- VAR N,count:INTEGER;
- BEGIN
- IF W=NIL
- THEN GetWindowNum:=0
- ELSE BEGIN
- N:=0;
- FOR count:=1 TO numWindows
- DO IF MyWindow[count]=W
- THEN N:=count;
- GetWindowNum:=N;
- END;
- END;
-
- {Standard Handling of the Menu. Selecting the Window Menu, bring that window}
- { to the front and that's all (Palette Manager handles changing colors and}
- { creating update). Animate Menu animate the front window if it can.}
- PROCEDURE DoCommand (mResult : LONGINT);
- VAR
- theItem : INTEGER;
- theMenu : INTEGER;
- name : Str255;
- N : INTEGER;
- dummy : Boolean;
- tempPort:GrafPtr;
- BEGIN
- theItem := LoWord(mResult);
- theMenu := HiWord(mResult);
- CASE theMenu OF
- appleM :
- IF theItem = 1 THEN
- theItem := Alert(AlertID, NIL)
- ELSE
- BEGIN
- GetItem(myMenus[appleM], theItem, name);
- N := OpenDeskAcc(name);
- END;
- fileM : CASE theItem OF
- 1: BEGIN
- GetPort(tempPort);
- SetPort(FrontWindow);
- CASE GetWindowNum(FrontWindow) OF
- ballW : AnimBall;
- shapeW : AnimShape;
- rainbowW : AnimRainbow;
- fadeW : AnimFade;
- OTHERWISE
- END;
- SetPort(tempPort);
- END;
- 2: CloseIt(GetWindowNum(FrontWindow));
- 4: doneFlag := TRUE;
- otherwise
- END;
- editM :
- dummy := SystemEdit(theItem - 1);
- winM : IF (theItem>0) and (theItem<=numWindows) THEN BEGIN
- IF MyWindow[theItem]=NIL THEN BEGIN
- CASE theItem OF
- redW :
- MakeRed;
- greenW :
- MakeGreen;
- blueW :
- MakeBlue;
- ballW :
- MakeBall;
- curW :
- MakeCur;
- shapeW :
- MakeShape;
- rainbowW :
- MakeRainbow;
- fadeW :
- MakeFade;
- OTHERWISE
- END;
- END
- ELSE SelectWindow(MyWindow[theItem]);
- END;
- OTHERWISE
- END;
- HiliteMenu(0);
- END;
-
- {Extremely Standard Main Program Loop.}
- PROCEDURE DoMainLoop;
- VAR
- theChar : CHAR;
- myEvent : EventRecord;
- whichWindow : WindowPtr;
- oldPort : GrafPtr;
- dummy : boolean;
- BEGIN
- REPEAT
- SystemTask;
- IF GetNextEvent(everyEvent, myEvent) THEN
- CASE myEvent.what OF
- mouseDown :
- CASE FindWindow(myEvent.where, whichWindow) OF
- inSysWindow :
- SystemClick(myEvent, whichWindow);
- inMenuBar :
- DoCommand(MenuSelect(myEvent.where));
- inGoAway: IF TrackGoAway(whichWindow,myEvent.where)
- THEN CloseIt(GetWindowNum(whichWindow));
- inDrag :
- IF (FrontWindow <> whichWindow) THEN
- SelectWindow(whichWindow)
- ELSE
- DragWindow(whichWindow, myEvent.where, dragRect);
- inContent :
- IF (FrontWindow <> whichWindow) THEN
- SelectWindow(whichWindow);
- OTHERWISE
- END; {of mouseDown}
- keyDown, autoKey :
- BEGIN
- theChar := CHR(BitAnd(myEvent.message, charCodeMask));
- IF BitAnd(myEvent.modifiers, cmdKey) <> 0 THEN
- DoCommand(MenuKey(theChar));
- END;
- updateEvt :
- BEGIN
- whichWindow := WindowPtr(myEvent.message);
- IF whichWindow <> NIL THEN
- BEGIN
- GetPort(oldPort);
- SetPort(whichWindow);
- BeginUpdate(whichWindow);
- CASE GetWindowNum(whichWindow) OF
- redW: DoRedUpdate;
- greenW: DoGreenUpdate;
- blueW: DoBlueUpdate;
- curW: DoCurUpdate;
- ballW: DoBallUpdate;
- shapeW: DoShapeUpdate;
- rainbowW: DoRainbowUpdate;
- fadeW: DoFadeUpdate;
- OTHERWISE
- END;
- EndUpdate(whichWindow);
- SetPort(oldPort);
- END;
- END;
- OTHERWISE
- END;
- UNTIL doneFlag;
- END;
-
- {Dispose of all the Palettes and closes all the Windows.}
- PROCEDURE CloseDown;
- VAR
- count : integer;
- BEGIN
- FOR count:=1 TO numWindows
- DO CloseIt(count);
- FOR count := appleM TO menuCount DO
- BEGIN
- DeleteMenu(count);
- DisposeMenu(myMenus[count]);
- END;
- DrawMenuBar;
- END;
-
- {Main Body Program. Setup, Do it, Close down.}
- BEGIN
- IF ColorQDExists THEN BEGIN
- SetUp;
- DoMainLoop;
- CloseDown;
- END;
- END.
-